package com.livegoods.mongodbdao;

import com.livegoods.pojo.House;
import com.mongodb.client.result.UpdateResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

@Repository
public class HouseDao4MongoDBImpl implements HouseDao4MongoDB {


    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public long update(String id) {

        Criteria criteria = Criteria.where("id").is(id);
        Query query = new Query(criteria);

        //修改出租状态为true
        Update isRented = Update.update("isRented", true);

        UpdateResult updateResult = mongoTemplate.updateFirst(query, isRented, House.class);


        long row = updateResult.getModifiedCount();


        return row;
    }
}
